<?php
/**
 * import/calcul.phtml
 */
$title = "Calcul Spécifique";
$this->headTitle($title);
?>
<ul>
    <li><a class="link-ajax" href="<?php echo $this->url('RHX/default', array('controller'	 => 'import', 'action'	 => 'calculateHeureTravail')) ?>">Calcul des Heures travaillées</a></li>
</ul>

<div id="result">
    <!-- AJAX CONTENT -->
</div>

<script type="text/javascript">
    $(function(){
	$('.link-ajax').click(function(e){
	    e.preventDefault();
	    href=$(this).attr('href');
	    perPage = 10;
	    ajaxPage = $.ajax({
		dataType: 'json',
		type: 'post',
		url : '<?php echo $this->url('RHX/default', array('controller'	 => 'import', 'action'	 => 'getPageCount')) ?>',
		data: 'perPage=' + perPage
	    });
	    ajaxPage.done(function(result){
		$('#result').hide('fast').html('').fadeIn('normal');
		nbPage = result.pageCount;
		for(i = 1; i <= nbPage; i++) {
				    ajaxCalcul = $.ajax({
					type: 'post',
					url: href,
					data: '&perPage=' + perPage + '&page=' + (i)
				    });
				    ajaxCalcul.done(function(data) {
					$('#result').append(data);
				    });
				}
			    });
			    ajaxPage.fail(function() {
				alert("Erreur Comptage page");
			    });
			});
		    });
</script>